﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana
{
	/// <summary>
	/// 场景怪物配表脚本
	/// </summary>
	[ExecuteInEditMode]
	public class SceneMonster : SceneObject
	{
#if UNITY_EDITOR
		[Header("Monster.xml表格ID")]
		[SerializeField]
		private int monsterId;

		[SerializeField]
		[Tooltip("怪物创建间隔")]
		private int spawnInterval = 1000;

		[SerializeField]
		[Tooltip("The number of the monster.")]
		private int num = 1;

		[SerializeField]
		[Tooltip("The total number this monster can be spawn.")]
		private int totalNum = 0;

		[SerializeField]
		[Tooltip("show icon on map")]
		private bool isShowMapIcon = false;

		[Header("预览对象资源")]
		[SerializeField]
		private AssetID previewAssetId;

		// The preview prefab.
		private GameObject previewPrefab;

		public int ID { get { return this.monsterId; } }
		public int Interval { get { return this.spawnInterval; } }
		public int Number { get { return this.num; } }
		public int TotalNum { get { return this.totalNum; } }
		public bool IsShowMapIcon { get { return this.isShowMapIcon; } }

		protected override bool HasPreview()
		{
			return this.previewPrefab != null;
		}

		protected override GameObject BuildPreview()
		{
			return Instantiate(this.previewPrefab);
		}

		void OnValidate()
		{
			if (Application.isPlaying) return;
			this.name = "Monster" + this.monsterId;
			if (!string.IsNullOrEmpty(previewAssetId.AssetGUID))
			{
				this.previewPrefab = previewAssetId.LoadObject<GameObject>();
			}
			else
			{
				//Debug.LogWarning("Can not find NPC with id: " + this.npcId);
				this.previewPrefab = null;
			}
			this.RefreshPreview();
		}



#endif

	}
}

